#include "Matrix.h"
#include <iostream>
using namespace std;

Matrix Matrix :: add(Matrix matrix2)							//I want to keep the matrix size variable depending on 
{																//user's choice. So using pointer to pointer
	Matrix result;
	result.allocate();
	for(int i=0; i<ORDER; i++)
		for(int j=0; j<ORDER; j++)
				result.matrix[i][j] = this->matrix[i][j] + matrix2.matrix[i][j];
	return result;
}

Matrix Matrix :: subtract(Matrix matrix2)
{
	Matrix result;
	result.allocate();
	for(int i=0; i<ORDER; i++)
		for(int j=0; j<ORDER; j++)
				result.matrix[i][j] = this->matrix[i][j] - matrix2.matrix[i][j];
	return result;
}

Matrix Matrix :: multiply(Matrix matrix2)														
{
	Matrix result;
	result.allocate();
	for(int i=0; i<ORDER; i++)
		for(int j=0; j<ORDER; j++)
		{
			result.matrix[i][j] = 0;
			for (int k=0; k<ORDER; k++)
				result.matrix[i][j]+= this->matrix[i][k]*matrix2.matrix[k][j];
		}
	return result;
}

void Matrix :: initialize(int inp[][ORDER])
{
	for(int i=0; i<ORDER; i++)
		for(int j=0; j<ORDER; j++)
			this->matrix[i][j] = inp[i][j];
}

void Matrix :: allocate()
{
	this->matrix = new int*[ORDER];	
	for(int i=0; i<ORDER; i++)	
		this->matrix[i]= new int[ORDER];
}

int Matrix :: get(int i, int j)
{
	return this->matrix[i][j];
}

void Matrix :: display()
{
	for(int i=0; i<ORDER; i++)
	{
		for(int j=0; j<ORDER; j++)
		{
			cout<<this->matrix[i][j]<<"\t";
		}
		cout<<endl;
	}
}

void get_input(int input[][ORDER])
{
	for(int i=0; i<ORDER; i++)
	{
		for(int j=0; j<ORDER; j++)
		{
			cout<<"Enter ("<<i<<", "<<j<<"):";
			cin>>input[i][j];
		}
	}
}